package router

import (
	"github.com/zhengchalei/gadmin/framework"
	"github.com/zhengchalei/gadmin/middleware"
	"github.com/zhengchalei/gadmin/project/system/api"
	"go.uber.org/zap"
)

func init() {
	// 启动
	defer start()
	// 认证模块
	auth()
	// 系统模块路由
	system()
}

func start() {
	if err := framework.Gin.Run(":8080"); err != nil {
		framework.Log.Error("Gin 启动失败! message", zap.Error(err))
		return
	}
}

func auth() {
	ag := framework.Gin.Group("/api/auth")
	{
		ag.POST("/login", middleware.AuthMiddleware.LoginHandler)
		ag.GET("/refresh_token", middleware.AuthMiddleware.RefreshHandler)
	}
}

func system() {
	sg := framework.Gin.Group("/api/system", middleware.AuthMiddleware.MiddlewareFunc())
	{
		ur := sg.Group("/user")
		{
			ur.GET("/all", api.UserAll)
			ur.GET("/page", api.UserPage)
			ur.POST("/save", api.UserSave)
			ur.POST("/update", api.UserUpdate)
			ur.DELETE("/delete", api.UserDelete)
		}
		dr := sg.Group("/dept")
		{
			dr.GET("/all", api.DeptAll)
			dr.GET("/page", api.UserPage)
			dr.POST("/save", api.UserSave)
			dr.POST("/update", api.UserUpdate)
			dr.DELETE("/delete", api.UserDelete)
		}
	}
}
